package cn.doctorpda.conference.ui.info;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cn.doctorpda.conference.R;
import cn.doctorpda.conference.ui.BaseFragment;

/**
 * Created by huangjinlong on 2016/5/17.
 */
public class InfoFragment extends BaseFragment implements View.OnClickListener {

    private String[] titles = new String[]{"  视频  ", "  PPT  ", "  文献  "};
    private TabLayout tab_layout;
    private ViewPager info_viewpager;
    private List<Fragment> fragments = new ArrayList<>();
    private FragmentPagerAdapter mPagerAdater;

    public static InfoFragment newInstance() {
        InfoFragment fragment = new InfoFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_info, container, false);
        initView(view);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    private void initData() {
        fragments.add(VideoFragment.newInstance());
        fragments.add(PPTFragment.newInstance());
        fragments.add(DocFragment.newInstance());

        mPagerAdater = new FragmentPagerAdapter(getActivity().getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        };
        info_viewpager.setAdapter(mPagerAdater);
        info_viewpager.setCurrentItem(0);
        tab_layout.setupWithViewPager(info_viewpager);
        tab_layout.setTabMode(TabLayout.MODE_FIXED);

        //添加tab
//            tab_layout.addTab(tab_layout.newTab().setText(titles[i]));
    }

    private void initView(View view) {
        tab_layout = (TabLayout) view.findViewById(R.id.tab_layout);
        info_viewpager = (ViewPager) view.findViewById(R.id.info_viewpager);
    }

    @Override
    public void onClick(View v) {
    }

    @Override
    public String getPageName() {
        return "InfoFragment";
    }


}
